{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from gs_quant.common import OptionType, OptionStyle\n",
    "from gs_quant.instrument import EqOption\n",
    "from gs_quant.markets import PricingContext\n",
    "from gs_quant.markets.securities import AssetIdentifier\n",
    "from gs_quant.risk.scenario_utils import *\n",
    "from gs_quant.session import Environment, GsSession\n",
    "from gs_quant.target.common import UnderlierType\n",
    "from datetime import date"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# external users should substitute their client id and secret; please skip this step if using internal jupyterhub\n",
    "GsSession.use(Environment.PROD, client_id=None, client_secret=None, scopes=('run_analytics','read_product_data'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# construct a vol override scenario.  \n",
    "\n",
    "# This example uses a sample vol dataset EDRVOL_PERCENT_EXPIRY_INTRADAY_PREMIUM_SAMPLE\n",
    "# Full dataset and additional info available in the data catalog:\n",
    "# https://marquee.gs.com/s/developer/datasets/EDRVOL_PERCENT_EXPIRY_INTRADAY_PREMIUM\n",
    "\n",
    "eq_vol_scenario = build_eq_vol_scenario_intraday('TMK UN', 'EDRVOL_PERCENT_EXPIRY_INTRADAY_PREMIUM_SAMPLE',  \n",
    "                                                 start_time=datetime(2019, 6, 3, 0, 0, 0), end_time=datetime(2019, 6, 4, 0, 0, 0),\n",
    "                                                 asset_name_type=AssetIdentifier.BLOOMBERG_ID)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Define an option and price with and without the vol override scenario\n",
    "\n",
    "option = EqOption('TMK UN', underlierType=UnderlierType.BBID, expirationDate='3m', strikePrice='ATM', \n",
    "                  optionType=OptionType.Call, optionStyle=OptionStyle.European)\n",
    "\n",
    "with PricingContext(date(2019,6,10)):\n",
    "    historic_option_price = option.price()      \n",
    "\n",
    "with PricingContext(date(2019,6,10)), eq_vol_scenario:\n",
    "    historic_option_vol_scenario_price = option.price()       \n",
    "\n",
    "# Look at the difference between scenario and base prices\n",
    "\n",
    "print('Base price:     {:,.2f}'.format(historic_option_price.result()))\n",
    "print('Scenario price: {:,.2f}'.format(historic_option_vol_scenario_price.result()))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "metadata": {
     "collapsed": false
    },
    "source": []
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
